MIDAS ClientDataSet


One of the most database engines problems is the size of that engine. When you deploy
applications that use the BDE or ADO, you have to install few megabytes of libraries
with special installation procedure. Some times you need to use less functionalities
of databases to develop small desktop applications such as telephone directory, so
why we install an engine that we used only 5% of it's power.

MIDAS ClientDataSet can be used as a stand-alone engine. It is very light database
engine.
ClientDataSet is very suitable for small desktop database applications that
deal with small and medium amount of data. Not like BDE and ADO which contain a lot
of libraries; MIDAS ClientDataSet requires only one library called
MIDAS.DLL. MIDAS.DLL
requires no registration or special installation procedure. The only thing you have
to do when deploying applications is to copy that file in your application directory
or in Windows system directory to be used with another applications. The size of
this file is about 260 K Bytes.
The big problem of
ClientDataSet is that it can't be used with standard databases
such as
Paradox, DBase, Access, and other formats, instead it stores it's table in
a special binary format.
ClientDataSet can export it's data in XML format.

Now as a
new feature of Delphi 6, you can add MidasLib unit to your unit's caluse
in each form you are using ClientDataSet component. In this case you will not need
to distribute Midas.dll file, instead all ClientDataSet functionality will be embedded
natively in your executable code, but you will increase it's size.


Using ClientDataSet:

The first thing we must talk about is how to create ClientDataSet tables( let us
appreviate it to
CDS).
Unfortunately Database Desktop does not support CDS tables, so that you have to
find another alternatives.
I'll describe two methods of creating
CDS files:

1.  Create CDS tables at design time:

- Drop a
ClientDataSet component.
- Right click in that component and select
Fields Editor.
- Right click on
Fields Editor and select New Field.
- Create the fields you want and close the
Field Editor.
- Right click on the
ClientDataSet component. At this time you will find a new menu
item called (
Create Dataset). Click on that item.
- Right click on
ClientDataSet1 and select SaveToFile, then select a file name for
example
First.cds:

 ClientDataSet1.FileName:= 'First.cds';
ClientDataSet1.SaveToFile;

2. Create CDS programatically (at run-time):

At run time you can create a CDS table. For example this is a Friends table:

procedure CreateFreindsTabe;
var
cdsTable: TClientDataSet;
begin

cdsTable:=
TClientDataSet.Create(nil);
// Create fields
 cdsTable.FieldDefs.Add('ID', ftAutoInc);
cdsTable.FieldDefs.Add('
Name', ftString, 30, True);
cdsTable.FieldDefs.Add('
DOB', ftDateTime);
cdsTable.FieldDefs.Add('
Notes', ftMemo, 70);

// Create primary index
 cdsTable.IndexDefs.Add('', 'ID',
  [ixPrimary, ixUnique]);

// Create the table with pre-defined fields
 cdsTable.CreateDataSet;

// Save the strucure to a physical file
 cdsTable.SaveToFile(AFileName);

// Release table instance
cdsTable.
Free;

end;


To open CDS file:

 ClientDataSet1.FileName:= 'First.cds';
ClientDataSet1.Open;

Data source, and Data Controls can be used with the CDS tables as any normal BDE
and ADO table.


The entire CDS table will be stored in a single file, which contains the structure
of the table, index, memo fields and all other properties.

For a complete example of using CDS tables see the attached example (
Telephone Directory)


PhoneDir.zip